

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>mindspore.DatasetHelper &mdash; MindSpore master documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="mindspore.connect_network_with_dataset" href="mindspore.connect_network_with_dataset.html" />
    <link rel="prev" title="mindspore.Model" href="mindspore.Model.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html" class="icon icon-home"> MindSpore
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">MindSpore Python API</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="../mindspore.html">mindspore</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id1">张量</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id2">参数</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id3">数据类型</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id4">随机种子</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id5">模型</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../mindspore.html#id6">数据处理工具</a><ul class="current">
<li class="toctree-l3 current"><a class="current reference internal" href="#">mindspore.DatasetHelper</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.connect_network_with_dataset.html">mindspore.connect_network_with_dataset</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id7">混合精度管理</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id8">序列化</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id9">即时编译</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id10">日志</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id11">自动混合精度</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id12">安装验证</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id13">调试</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id14">内存回收</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.common.initializer.html">mindspore.common.initializer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.communication.html">mindspore.communication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.compression.html">mindspore.compression</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.context.html">mindspore.context</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.html">mindspore.dataset</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.audio.html">mindspore.dataset.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.config.html">mindspore.dataset.config</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.text.html">mindspore.dataset.text</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.transforms.html">mindspore.dataset.transforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.vision.html">mindspore.dataset.vision</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.mindrecord.html">mindspore.mindrecord</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.html">mindspore.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.probability.html">mindspore.nn.probability</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.transformer.html">mindspore.nn.transformer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.numpy.html">mindspore.numpy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.ops.html">mindspore.ops</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.html">mindspore.parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.nn.html">mindspore.parallel.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.profiler.html">mindspore.profiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.scipy.html">mindspore.scipy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.train.html">mindspore.train</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.boost.html">mindspore.boost</a></li>
</ul>
<p class="caption"><span class="caption-text">MindSpore C++ API</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html">MindSpore Lite↗</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">MindSpore</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../mindspore.html">mindspore</a> &raquo;</li>
        
      <li>mindspore.DatasetHelper</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../_sources/api_python/mindspore/mindspore.DatasetHelper.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="mindspore-datasethelper">
<h1>mindspore.DatasetHelper<a class="headerlink" href="#mindspore-datasethelper" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="mindspore.DatasetHelper">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.</code><code class="sig-name descname">DatasetHelper</code><span class="sig-paren">(</span><em class="sig-param">dataset</em>, <em class="sig-param">dataset_sink_mode=True</em>, <em class="sig-param">sink_size=-1</em>, <em class="sig-param">epoch_num=1</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.DatasetHelper" title="Permalink to this definition">¶</a></dt>
<dd><p>DatasetHelper是一个处理MindData数据集的类，提供数据集信息。</p>
<p>根据不同的上下文，改变数据集的迭代，在不同的上下文中使用相同的迭代。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>DatasetHelper的迭代将提供一个epoch的数据。</p>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>dataset</strong> (Dataset) - 训练数据集迭代器。数据集可以由数据集生成器API在 <code class="xref py py-class docutils literal notranslate"><span class="pre">mindspore.dataset</span></code> 中生成，例如 <a class="reference internal" href="../dataset/mindspore.dataset.ImageFolderDataset.html#mindspore.dataset.ImageFolderDataset" title="mindspore.dataset.ImageFolderDataset"><code class="xref py py-class docutils literal notranslate"><span class="pre">mindspore.dataset.ImageFolderDataset</span></code></a> 。</p></li>
<li><p><strong>dataset_sink_mode</strong> (bool) - 如果值为True，使用 <a class="reference internal" href="../ops/mindspore.ops.GetNext.html#mindspore.ops.GetNext" title="mindspore.ops.GetNext"><code class="xref py py-class docutils literal notranslate"><span class="pre">mindspore.ops.GetNext</span></code></a> 在设备（Device）上通过数据通道中获取数据，否则在主机（Host）直接遍历数据集获取数据。默认值：True。</p></li>
<li><p><strong>sink_size</strong> (int) - 控制每个下沉中的数据量。如果 <cite>sink_size</cite> 为-1，则下沉每个epoch的完整数据集。如果 <cite>sink_size</cite> 大于0，则下沉每个epoch的 <cite>sink_size</cite> 数据。默认值：-1。</p></li>
<li><p><strong>epoch_num</strong> (int) - 控制待发送的epoch数据量。默认值：1。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">mindspore</span> <span class="kn">import</span> <span class="n">DatasetHelper</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">train_dataset</span> <span class="o">=</span> <span class="n">create_custom_dataset</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">set_helper</span> <span class="o">=</span> <span class="n">DatasetHelper</span><span class="p">(</span><span class="n">train_dataset</span><span class="p">,</span> <span class="n">dataset_sink_mode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">net</span> <span class="o">=</span> <span class="n">Net</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Object of DatasetHelper is iterable</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">next_element</span> <span class="ow">in</span> <span class="n">set_helper</span><span class="p">:</span>
<span class="gp">... </span>    <span class="c1"># `next_element` includes data and label, using data to run the net</span>
<span class="gp">... </span>    <span class="n">data</span> <span class="o">=</span> <span class="n">next_element</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="gp">... </span>    <span class="n">net</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
<dl class="method">
<dt id="mindspore.DatasetHelper.continue_send">
<code class="sig-name descname">continue_send</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.DatasetHelper.continue_send" title="Permalink to this definition">¶</a></dt>
<dd><p>在epoch开始时继续向设备发送数据。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.DatasetHelper.dynamic_min_max_shapes">
<code class="sig-name descname">dynamic_min_max_shapes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.DatasetHelper.dynamic_min_max_shapes" title="Permalink to this definition">¶</a></dt>
<dd><p>返回动态数据的形状(shape)范围（最小形状(shape)，最大形状(shape)）。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">mindspore</span> <span class="kn">import</span> <span class="n">DatasetHelper</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">train_dataset</span> <span class="o">=</span> <span class="n">create_custom_dataset</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># config dynamic shape</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span><span class="o">.</span><span class="n">set_dynamic_columns</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;data1&quot;</span><span class="p">:</span> <span class="p">[</span><span class="mi">16</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="mi">83</span><span class="p">],</span> <span class="s2">&quot;data2&quot;</span><span class="p">:</span> <span class="p">[</span><span class="kc">None</span><span class="p">]})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset_helper</span> <span class="o">=</span> <span class="n">DatasetHelper</span><span class="p">(</span><span class="n">train_dataset</span><span class="p">,</span> <span class="n">dataset_sink_mode</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">min_shapes</span><span class="p">,</span> <span class="n">max_shapes</span> <span class="o">=</span> <span class="n">dataset_helper</span><span class="o">.</span><span class="n">dynamic_min_max_shapes</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.DatasetHelper.get_data_info">
<code class="sig-name descname">get_data_info</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.DatasetHelper.get_data_info" title="Permalink to this definition">¶</a></dt>
<dd><p>下沉模式下，获取当前批次数据的类型和形状(shape)。通常在数据形状(shape)动态变化的场景使用。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.DatasetHelper.release">
<code class="sig-name descname">release</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.DatasetHelper.release" title="Permalink to this definition">¶</a></dt>
<dd><p>释放数据下沉资源。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.DatasetHelper.sink_size">
<code class="sig-name descname">sink_size</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.DatasetHelper.sink_size" title="Permalink to this definition">¶</a></dt>
<dd><p>获取每次迭代的 <cite>sink_size</cite> 。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">mindspore</span> <span class="kn">import</span> <span class="n">DatasetHelper</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">train_dataset</span> <span class="o">=</span> <span class="n">create_custom_dataset</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset_helper</span> <span class="o">=</span> <span class="n">DatasetHelper</span><span class="p">(</span><span class="n">train_dataset</span><span class="p">,</span> <span class="n">dataset_sink_mode</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">sink_size</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># if sink_size==-1, then will return the full size of source dataset.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sink_size</span> <span class="o">=</span> <span class="n">dataset_helper</span><span class="o">.</span><span class="n">sink_size</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.DatasetHelper.stop_send">
<code class="sig-name descname">stop_send</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.DatasetHelper.stop_send" title="Permalink to this definition">¶</a></dt>
<dd><p>停止发送数据下沉数据。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.DatasetHelper.types_shapes">
<code class="sig-name descname">types_shapes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.DatasetHelper.types_shapes" title="Permalink to this definition">¶</a></dt>
<dd><p>从当前配置中的数据集获取类型和形状(shape)。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">mindspore</span> <span class="kn">import</span> <span class="n">DatasetHelper</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">train_dataset</span> <span class="o">=</span> <span class="n">create_custom_dataset</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset_helper</span> <span class="o">=</span> <span class="n">DatasetHelper</span><span class="p">(</span><span class="n">train_dataset</span><span class="p">,</span> <span class="n">dataset_sink_mode</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">types</span><span class="p">,</span> <span class="n">shapes</span> <span class="o">=</span> <span class="n">dataset_helper</span><span class="o">.</span><span class="n">types_shapes</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="mindspore.connect_network_with_dataset.html" class="btn btn-neutral float-right" title="mindspore.connect_network_with_dataset" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="mindspore.Model.html" class="btn btn-neutral float-left" title="mindspore.Model" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2021, MindSpore.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>